package com.soft.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.soft.pojo.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserLogin {

/*    public static void main(String[] args) {
        User admin = login("admin", "123456");
        System.out.println(admin.getUsername());
    }*/

    public static User login(String username, String password) {
        QueryRunner queryRunner = new QueryRunner(new ComboPooledDataSource());

        try {
            User user = queryRunner.query("select * from user where username = ? and password = ?;", new BeanHandler<User>(User.class), username, password);
            return  user;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return null;
    }
}
